﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebsiteBanThucAn.Models;
using BLL;

namespace WebsiteBanThucAn.Controllers
{ 
    public class ProductController : Controller
    {
        private HappyFastFoodContext db = new HappyFastFoodContext();

        //
        // GET: /Product/

        public ViewResult Index()
        {
            return View(db.MonAns.ToList());
        }

        //
        // GET: /Product/Details/5

        public ViewResult Details(int id)
        {
            MonAnModel monanmodel = db.MonAns.Find(id);
            return View(monanmodel);
        }

        //
        // GET: /Product/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Product/Create

        [HttpPost]
        public ActionResult Create(MonAnModel monanmodel)
        {
            bool result = MonAnBLL.ThemMonAn(monanmodel);
            if (ModelState.IsValid && result)
            {
                db.MonAns.Add(monanmodel);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(monanmodel);
        }
        
        //
        // GET: /Product/Edit/5
 
        public ActionResult Edit(int id)
        {
            MonAnModel monanmodel = db.MonAns.Find(id);
            return View(monanmodel);
        }

        //
        // POST: /Product/Edit/5

        [HttpPost]
        public ActionResult Edit(MonAnModel monanmodel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(monanmodel).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(monanmodel);
        }

        //
        // GET: /Product/Delete/5
 
        public ActionResult Delete(int id)
        {
            MonAnModel monanmodel = db.MonAns.Find(id);
            return View(monanmodel);
        }

        //
        // POST: /Product/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            MonAnModel monanmodel = db.MonAns.Find(id);
            db.MonAns.Remove(monanmodel);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}